package com.test.mapper.enitites;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

public class EntityProperty implements Serializable {

	/**
	 * Generated serial version UID.
	 */
	private static final long serialVersionUID = -6098954459715267174L;

	private int clientId;

	private String tableName;
	
	private String columnName;

	private String propertyName;

	private PropertyType propertyType;

	private int fieldLength;

	private boolean unique = false;

	private EntityProperty foreignKeyTo = null;
	
	private EntityModel foreignModel = null;

	public EntityProperty() {
		// default constructor
	}

	public EntityProperty(final String name, final PropertyType type) {
		if (StringUtils.isEmpty(name) || type == null) {
			throw new NullPointerException("Property name and type must be not empty");
		}
		init(name, type);
	}

	public EntityProperty(final EntityProperty otherProperty) {
		if (otherProperty == null || StringUtils.isEmpty(otherProperty.getPropertyName())
				|| otherProperty.getPropertyType() == null) {
			throw new NullPointerException("Cannot create empty or partially empty property");
		}
		init(otherProperty.getPropertyName(), otherProperty.getPropertyType());
	}

	private void init(final String name, final PropertyType type) {
		this.propertyName = new String(name);
		this.propertyType = PropertyType.valueOf(type.name());;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public PropertyType getPropertyType() {
		return propertyType;
	}

	public void setPropertyType(PropertyType propertyType) {
		this.propertyType = propertyType;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public boolean isUnique() {
		return unique;
	}

	public void setUnique(boolean unique) {
		this.unique = unique;
	}

	public EntityProperty getForeignKeyTo() {
		return foreignKeyTo;
	}

	public void setForeignKeyTo(EntityProperty foreignKeyTo) {
		this.foreignKeyTo = foreignKeyTo;
	}

	public int getFieldLength() {
		return fieldLength;
	}

	public void setFieldLength(int fieldLength) {
		this.fieldLength = fieldLength;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public int getClientId() {
		return clientId;
	}

	public void setClientId(int clientId) {
		this.clientId = clientId;
	}

	public EntityModel getForeignModel() {
		return foreignModel;
	}

	public void setForeignModel(EntityModel foreignModel) {
		this.foreignModel = foreignModel;
	}
}
